//
//  NYUpdateUserInfoForm.m
//  NYTYY
//
//  Created by 袁航 on 2017/12/9.
//  Copyright © 2017年 NYtyy. All rights reserved.
//

#import "NYUpdateUserInfoForm.h"
#import "NYUpdateUserInfoCell.h"
#import "NYUpdateUserInfoHeadImgCell.h"
#import "NYModifyInfoViewController.h"
NSString *const NYUpdateUserInfoFormCustomCell = @"NYUpdateUserInfoFormCustomCell";
//NSString *const NYUpdateUserInfoRowDescriptorTypeNickName = @"NYUpdateUserInfoRowDescriptorTypeNickName";
//NSString *const NYUpdateUserInfoRowDescriptorTypeReaNYame = @"NYUpdateUserInfoRowDescriptorTypeReaNYame";
//NSString *const NYUpdateUserInfoRowDescriptorTypePhone = @"NYUpdateUserInfoRowDescriptorTypePhone";
//NSString *const NYUpdateUserInfoRowDescriptorTypeIDNumber = @"NYUpdateUserInfoRowDescriptorTypeIDNumber";
//NSString *const NYUpdateUserInfoRowDescriptorTypeGender = @"NYUpdateUserInfoRowDescriptorTypeGender";
//NSString *const NYUpdateUserInfoRowDescriptorTypeBirthday = @"NYUpdateUserInfoRowDescriptorTypeBirthday";
//NSString *const NYUpdateUserInfoRowDescriptorTypeAddress = @"NYUpdateUserInfoRowDescriptorTypeAddress";
//NSString *const NYUpdateUserInfoRowDescriptorTypeEmail = @"NYUpdateUserInfoRowDescriptorTypeEmail";

@implementation NYUpdateUserInfoForm
- (instancetype)initWithTitle:(NSString *)title
{
        self = [super initWithTitle:title];
        if (self)
        {
                [self initializeForm];
        }
        return self;
}
- (void)initializeForm
{
        __block XLFormSectionDescriptor * section;
        __block XLFormRowDescriptor * row;
        // 头像
        section = [XLFormSectionDescriptor formSectionWithTitle:@"HeadImg"];
        [self addFormSection:section];
        row = [XLFormRowDescriptor formRowDescriptorWithTag:@"order" rowType:XLFormRowDescriptorTypeImage];
        row.value = NYUserManager.avatar;
        row.title = @"头像";
        row.cellClass = [NYUpdateUserInfoHeadImgCell class];
        [section addFormRow:row];
        
        // 底部视图
        NSArray <NSString *>*titlesArr = @[@"昵称"/*,@"真实姓名",@"手机号码",@"身份证号码",@"性别",@"出生日期",@"联系地址",@"邮箱"*/];
        NSArray <NSString *>*tags = @[
                                      @keypath(NYUserManager,nickname),
//                                       @keypath(NYUserManager,name),
//                                       @keypath(NYUserManager,mobile),
//                                       @keypath(NYUserManager,id_number),
//                                       @keypath(NYUserManager,gender),
//                                       @keypath(NYUserManager,date),
//                                       @keypath(NYUserManager,address),
//                                       @keypath(NYUserManager,email)
                                       ];
        section = [XLFormSectionDescriptor formSectionWithTitle:@"Other"];
        [self addFormSection:section];
        
        for (int i = 0; i < NYUpdateUserInfoTypeMax; i++)
        {
                row = [XLFormRowDescriptor formRowDescriptorWithTag:tags[i] rowType:@(i).stringValue title:titlesArr[i]];
                row.value = NOT_NULL_STRING([NYUserManager valueForKey:tags[i]],@"");
                row.subTitle = NOT_NULL_STRING([NYUserManager valueForKey:tags[i]],@"未设置");
                row.cellClass = [NYUpdateUserInfoCell class];
                row.action.viewControllerClass = [NYModifyInfoViewController class];
                row.onChangeBlock = ^(id  _Nullable oldValue, id  _Nullable newValue, XLFormRowDescriptor * _Nonnull rowDescriptor) {
                        [NYUserManager setValue:newValue forKey:rowDescriptor.tag];
                };
                [section addFormRow:row];
        }
}
@end
